<template>
  <view class="openmarket">
    <view class="title">
      <image
        src="@/static/noitce.png"
        class="icon-time"
        mode="aspectFill"
      />
      <view class="text">
        消息公告
      </view>
    </view>
    <view class="content-view">
      <view
        v-for="(notice, id) in notices"
        :key="id"
        class="content-item"
        @click="ngtdetail(notice)"
      >
        <view class="item-title">
          {{ notice.title }}
        </view>
        <view class="desc">
          {{ notice.content }}
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { homemock } from '@/config/mock'
import eventbus from '@/common/emitter'
export default {
  components: {},
  props: {
    full: {
      type: Boolean,
      value: false
    },
    num: {
      type: [Number,String],
      default: 6
    }
  },
  data () {
    return {
      notices: [],
     
    }
  },
  computed: {},
  watch: {},
  mounted () {
    this.queryfilter = {
      size: this.num,
      current: 1
    }
    if (this.full) {
      this.queryfilter.size = 10
    }
    this.total=0
    if(!this.$store.state.hasLogin){
      eventbus.on('loginSuccess',()=>{
        this.querydata()
      })
      return
    }
    this.querydata()
  },
  methods: {
    ngtdetail(notice){
      uni.navigateTo({
        url: `/pages/notice/detail?id=${notice.id}`
      })

    },
    querydata () {
      const _this = this
      // _this.notices = homemock.notices
      _this.$http.post('/notice/query', _this.queryfilter).then(res => {
        if(res.success){
          let data=res.data
          _this.notices = data.records
          _this.total=data.total
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.openmarket {
  width: 100%;
  .title {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-bottom: 24rpx;
    .icon-time {
      width: 32rpx;
      height: 32rpx;
      margin-right: 10rpx;
    }
    .text {
      font-family: AdobeHeitiStd-Regular;
      font-size: 32rpx;
      font-weight: normal;
      font-stretch: normal;
      color: #444444;
    }
  }
  .content-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    .content-item {
      width: 700rpx;
      // height: 165rpx;
      background-color: #ffffff;
      border-radius: 8rpx;
      padding: 26rpx 32rpx;
      margin-bottom: 17rpx;
      .item-title {
        font-family: PingFangSC-Medium;
        font-size: 32rpx;
        font-weight: normal;
        font-stretch: normal;
        color: #444444;
      }
      .desc {
        margin-top: 20rpx;
        font-family: AdobeHeitiStd-Regular;
        font-size: 26rpx;
        font-weight: normal;
        font-stretch: normal;
        color: #666666;
         text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
      }
    }
  }
}
</style>
